package com.jieyun.rbac.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jieyun.core.component.page.Pager;
import com.jieyun.core.utils.ServerResponse;
import com.jieyun.rbac.param.SysRoleParam;
import com.jieyun.rbac.po.SysRole;
import com.jieyun.rbac.service.SysRoleService;

/**
 * 系统角色controller
 * 
 * @author trekxu
 *
 */
@Controller
@RequestMapping("/sys/role")
public class SysRoleController {

	@Resource
	private SysRoleService sysRoleService;

	/**
	 * 返回到角色和权限首页
	 * @return
	 */
	@RequestMapping("index")
	public String index() {
		return  "/sys/role";
	}
	
	/**
	 * 系统角色
	 * 
	 * @param sysRole
	 * @return
	 */
	@RequestMapping("/add")
	@ResponseBody
	public ServerResponse roleAdd(@Validated SysRoleParam sysRole) {
		return this.sysRoleService.addRole(sysRole);
	}

	/**
	 * 系统用户冻结或者激活
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping("onOrOff")
	public ServerResponse roleOnOrOff(Integer id) {
		return this.sysRoleService.roleOnOrOffRole(id);
	}

	/**
	 * 系统角色更新
	 * 
	 * @param sysRole
	 * @return
	 */
	@RequestMapping("update")
	@ResponseBody
	public ServerResponse roleUpdate(Integer id, String name, String remark) {
		return this.sysRoleService.roleUpdate(id, name, remark);
	}

	/**
	 * 系统角色列表
	 * 
	 * @param type
	 * @return
	 */
	@ResponseBody
	@RequestMapping("list")
	public Pager<SysRole> roleList(Integer type) {
		List<SysRole> roleList = this.sysRoleService.roleList(type);
		return 	Pager.adapt(roleList);
	}
}
